﻿
package com.game.chat
{
    import com.game.chat.json.JSON;
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    
    import com.game.main.MainCanvas;
    
    import mx.controls.VScrollBar;   

    public class RichTextField extends Sprite {

        public var _spriteContainer:Sprite;
        private var _length:int;
        private var _format:Dictionary;
        private var _spriteHspace:int;
        private var _enabled:Boolean= true;
        
        private var _defaultTextFormat:TextFormat = new TextFormat("Courier New", 12, 0xF7F892, false);
        private var PLACEHOLDER_FONT:String = "Arial";
        private var _selectEnd:int;
        public var lineHeight:Number;
        private var _selectBegin:int;
        private var PLACEHOLDER:String = "﹒";
        private var _spriteVspace:int;
        private var PLACEHOLDER_COLOR:uint = 0;
        private var _scrollV:int;
        public var autoScroll:Boolean;
        private var _textfield:TextField;
        private var _spriteMask:Shape;
        private var _replacing:Boolean;
        public var autoScrollV:int = 0;
        
        public var vScrollBar:VScrollBar = null;
        
        public static const INPUT:String = "input";
        private static const ADJUST_TYPE_CHANGE:String = "adjust_type_change";
        private static const ADJUST_TYPE_INSERT:String = "adjust_type_insert";
        public static const DYNAMIC:String = "dynamic";
		public var chatCanvas:ChatCanvas;
		
        public function RichTextField(w:Number, h:Number, type:String="dynamic"){
        	
            initTextField(w, h);
            addChild(_textfield);
            _textfield.maxChars=60;
            _textfield.addEventListener(MouseEvent.CLICK,mouseClickText);
            
            _spriteContainer = new Sprite();
            addChild(_spriteContainer);
            _format = new Dictionary();
            _scrollV = 1;
            lineHeight = h;
            _spriteHspace = (_spriteVspace = 1);
            this.type = type;
            _spriteMask = createSpritesMask(_textfield.x, _textfield.y, _textfield.width, _textfield.height);
            addChild(_spriteMask);
            _spriteContainer.mask = _spriteMask;
        }
         private function mouseClickText(e:Event){
        	if(!chatCanvas)return;
        	var start:int=_textfield.selectionBeginIndex;
        	var name:String="";
        	var leftEnd:Boolean=false;
        	var rightEnd:Boolean=false;
        	var leftChar:String="";
        	var rightChar:String="";
        	var leftIdx:int=start;
        	var rightIdx:int=start-1;
        
        	if(start>=0 && start<_textfield.length){
        		while(!leftEnd || !rightEnd ){
         
        			leftIdx=leftIdx-1;
        			if(leftIdx<0)leftEnd=true;
        			rightIdx=rightIdx+1;
        			if(rightIdx>=_textfield.length)rightEnd=true;
        			if(!leftEnd){
        				leftChar=_textfield.text.substr(leftIdx,1);
        				if(leftChar=="\n" || leftChar=="\r"|| leftChar==":"|| leftChar=="]"|| leftChar=="["|| leftChar=="对"){
        					leftEnd=true;
        				}else{
        					name=leftChar+name;
        				}
        			}
        			if(!rightEnd){
        				rightChar=_textfield.text.substr(rightIdx,1);
        				if(rightChar=="\n"|| rightChar=="\r" || rightChar=="说"|| rightChar=="[" || rightChar=="]" || rightChar=="对"){
        					rightEnd=true;
        				}else{
        					name=name+rightChar;
        				}
        			}
        			if(name.length>20){
        				leftEnd=true;
        				rightEnd=true;
        				name="";
        			}
        		}
        		 
        	    chatCanvas.checkUser(name);
         
        	}
        }        
        public function setBgColor(hasBgColor:Boolean,c:uint):void
        {
            _textfield.background = hasBgColor;
            _textfield.backgroundColor = c;        	
        }

        public function limit(num:int):void
        {
        	_textfield.text = _textfield.text.substring(0,30);
        }

        public function setForeColor(c:uint,f:Array=null):void
        {
            this.defaultTextFormat.color = c;
            if(f){
            	this._textfield.filters = f;
            }
        }
        
        public function setMutiable(b:Boolean):void
        {
        	this._textfield.multiline = b;

        }
        
        public function setVScrollBar(bar:VScrollBar):void
        {
        	this.vScrollBar = bar;
        }
        
        private function changeHandler(_arg1:Event):void{
            var _local2:int = (_textfield.length - _length);
            _length = _textfield.length;
            var _local3:int = _textfield.caretIndex;
            if (_local2 < 0){
                checkSpriteExist(_textfield.caretIndex, _local2);
                adjustSprites(_textfield.caretIndex, _local2, ADJUST_TYPE_CHANGE);
            } else {
                adjustSprites(((_textfield.caretIndex - _local2) + 1), _local2, ADJUST_TYPE_CHANGE);
            };
        }
        
        public function set enabled(b:Boolean):void
        {
        	this._enabled = b;

        }
        
        public function get numSprite():int{
            return (_spriteContainer.numChildren);
        }
        public function setTextFormat(_arg1:TextFormat, _arg2:int=-1, _arg3:int=-1):void{
            if ((((_arg2 > -1)) && ((_arg2 == _arg3)))){
                return;
            };
            if (_arg3 < 0){
                if (_arg2 < 0){
                    _arg3 = _textfield.text.length;
                } else {
                    _arg3 = (_arg2 + 1);
                };
            };
            if (_arg2 < 0){
                _arg2 = 0;
            };
            if (_arg3 <= _arg2){
                return;
            };
            _textfield.setTextFormat(_arg1, _arg2, _arg3);
            recoverPlaceholderFormat(_arg2, _arg3);
            _format[{begin:_arg2, end:_arg3}] = _arg1;
            adjustCoordinate(_arg2, (_textfield.text.length - 1));
        }
        public function copyFromRichText(_arg1:RichTextField, _arg2:int=-1, _arg3:int=-1, _arg4:Boolean=true):void{
            var _local9:String;
            var _local10:Sprite;
            recoverDefaultTextFormat();
            var _local5:int = _textfield.text.length;
            if ((((_arg2 == -1)) && ((_arg3 == -1)))){
                _arg2 = 0;
                _arg3 = (_arg1.textfield.text.length - 1);
            } else {
                if (_arg3 == -1){
                    _arg3 = _arg2;
                };
            };
            var _local6:String = _arg1.textfield.text.substring(_arg2, (_arg3 + 1));
            if (_arg4){
                _local6 = (_local6 + "\n");
            };
            _local6 = _local6.split("\r").join("\n");
            _textfield.text = _local6;
            applyTextFormat(_arg1.format, _local5);
            var _local7:int;
            var _local8:int = _local6.length;
            while (_local7 < _local8) {
                _local9 = _local6.charAt(_local7);
                if (_local9 == PLACEHOLDER){
                    _local10 = _arg1.getSpriteByName(String(_local7));
                    if (_local10){
                        _textfield.replaceText((_local5 + _local7), ((_local5 + _local7) + 1), "");
                        addSprite(_local10, (_local5 + _local7), _local10.width, _local10.height);
                    };
                };
                _local7++;
            };
        }
        public function set spriteHspace(_arg1:int):void{
            _spriteHspace = _arg1;
        }
        public function isSprite(_arg1:int):Boolean{
            if ((((_arg1 < 0)) || ((_arg1 >= length)))){
                return (false);
            };
            return ((_textfield.text.charAt(_arg1) == PLACEHOLDER));
        }
        private function checkSpriteExist(_arg1:int, _arg2:int):void{
            var _local6:Sprite;
            var _local7:int;
            var _local3:int = ((_arg1 + _arg2) + 1);
            var _local4:int = (_arg1 + 1);
            if ((((_arg2 < -1)) && (!((_selectBegin == _selectEnd))))){
                _local3 = _selectBegin;
                _local4 = _selectEnd;
            };
            var _local5:int = _local3;
            while (_local5 < _local4) {
                _local6 = (_spriteContainer.getChildByName(String(_local5)) as Sprite);
                if (_local6){
                    _local7 = _spriteContainer.getChildIndex(_local6);
                    _spriteContainer.removeChild(_local6);
                };
                _local5++;
            };
        }
        private function applyTextFormat(_arg1:Dictionary, _arg2:int):void{
            var _local3:Object;
            var _local4:int;
            var _local5:int;
            for (_local3 in _arg1) {
                _local4 = (_local3.begin + _arg2);
                _local5 = (_local3.end + _arg2);
                setTextFormat(_arg1[_local3], _local4, _local5);
            };
        }
        private function getSelectionHandler(_arg1:MouseEvent):void{
            _selectBegin = _textfield.selectionBeginIndex;
            _selectEnd = _textfield.selectionEndIndex;
        }
        public function setCaretIndex(_arg1:int):void{
            _textfield.setSelection(_arg1, _arg1);
        }
        private function getPlaceholderFormat(w:Number, h:Number):TextFormat{
            var _local3:TextFormat = new TextFormat();
            _local3.font = PLACEHOLDER_FONT;
            _local3.color = PLACEHOLDER_COLOR;
            _local3.size = (h + (2 * _spriteVspace));
            _local3.underline = false;
            _local3.letterSpacing = (((w - h) - (2 * _spriteVspace)) + (2 * _spriteHspace));
            
            _local3.size = 11;
            
            
            _local3.letterSpacing = 12;
            
            return (_local3);
        }
        
        
        private function initTextField(_arg1:Number, _arg2:Number):void{
            _textfield = new TextField();

            _textfield.width = _arg1;
            _textfield.height = _arg2;
            
            _textfield.multiline = true;
            _textfield.wordWrap = true;
            _textfield.restrict = ("^" + PLACEHOLDER);
        }
        private function setSpriteCoordinate(s:Sprite, r:Rectangle):void{
            s.x = ((_spriteContainer.x + r.left) + _spriteHspace);
           
            //s.y = (((r.top + r.height) - s.height) - _spriteVspace);
            s.y =  r.top - _spriteVspace;
        }
        private function inputHandler(_arg1:Event):void{
            recoverDefaultTextFormat();
        }
        private function recoverDefaultTextFormat():void{
            if (_defaultTextFormat){
               defaultTextFormat = _defaultTextFormat;
               _textfield.defaultTextFormat = _defaultTextFormat;
            };
        }
        public function getSpriteByName(_arg1:String):Sprite{
            return ((_spriteContainer.getChildByName(_arg1) as Sprite));
        }
        public function get defaultTextFormat():TextFormat{
            return (_defaultTextFormat);
        }
        public function scrollTo(_arg1:int):void{
            if (_textfield.scrollV != _arg1){
                _textfield.scrollV = _arg1;
            };
        }

        public function onScrollBar(_arg1:Number):void{
        	var curP:int = Math.floor(_textfield.maxScrollV*_arg1);
			scrollTo(curP);
        }
        
         public function getMsgText(_arg1:RichTextField)
        {
            var msg:String = _arg1.textfield.text.substring(0, _arg1.textfield.text.length );

            msg = msg.split("\r").join("\n");

            msg = msg.split(PLACEHOLDER).join("");
            return msg;       	
        }

        public function getMsgFaces(_arg1:RichTextField)
        {
            var _local6:String = _arg1.textfield.text.substring(0, _arg1.textfield.text.length );

            _local6 = _local6.split("\r").join("\n");

            var _local7:int;
            var _local8:int = _local6.length;

            var _local9:String;
            var _local10:Sprite;

			var aIcons:Array = new Array();
			var sDef:Object  = new Object();
            while (_local7 < _local8) {
                _local9 = _local6.charAt(_local7);
                if (_local9 == PLACEHOLDER){
                    _local10 = _arg1.getSpriteByName(String(_local7));
					
					sDef.src = getQualifiedClassName(_local10);
					sDef.index = _local7-aIcons.length;
					
					aIcons.push(JSON.encode(sDef));
                };
                _local7++;
            };
            
            return aIcons;       	
        }        
        		
				
		public function appendRichText2(_arg1:String,prefixSize:int, _arg2:Array=null, _arg3:TextFormat=null, _arg4:Boolean=true):void{
            var _local5:int;
            var _local6:int;
            if (_arg1){
				
		
                appendText(_arg1, _arg3, _arg4);
            };
            if (_arg2){
                _local5 = 0;
                while (_local5 < _arg2.length) {
					var eFace:Object = JSON.decode(_arg2[_local5]);
                    _local6 = eFace.index+prefixSize;
                    if (_local6 == -1){
                        _local6 = _arg1.length;
                    } else {
                        if (_arg4){
                            _local6--;
                        };
                    };
                    _local6 = (_local6 + (_textfield.length - _arg1.length));
                    if (((_arg4) && ((_local6 >= _textfield.length)))){
                        _local6 = (_textfield.length - 1);
                    };
					
					var spriteFace:Class = getDefinitionByName( eFace.src) as Class;
                    //addSprite( spriteFace, _local6, -1, lineHeight);
                    addSprite( spriteFace, _local6, -1, -1);
                    _local5++;
                };
            };
            if (autoScroll){
                scrollTo(_textfield.maxScrollV);
	            if(this.vScrollBar){
	            	vScrollBar.scrollPosition = _textfield.maxScrollV;
	            }                
            } else {
                if (autoScrollV > 0){
                    scrollTo(autoScrollV);
                };
            };
        }				   
        
        
        public function appendFromRichText(_arg1:RichTextField, _arg2:int=-1, _arg3:int=-1, _arg4:Boolean=true):void{
            var _local9:String;
            var _local10:Sprite;
            recoverDefaultTextFormat();
            var _local5:int = _textfield.text.length;
            if ((((_arg2 == -1)) && ((_arg3 == -1)))){
                _arg2 = 0;
                _arg3 = (_arg1.textfield.text.length - 1);
            } else {
                if (_arg3 == -1){
                    _arg3 = _arg2;
                };
            };
            var _local6:String = _arg1.textfield.text.substring(_arg2, (_arg3 + 1));
            if (_arg4){
                _local6 = (_local6 + "\n");
            };
            _local6 = _local6.split("\r").join("\n");
            _textfield.appendText(_local6);
            applyTextFormat(_arg1.format, _local5);
            var _local7:int;
            var _local8:int = _local6.length;
			
			var aIcons:Array = new Array();
			var sDef:Object  = new Object();
            while (_local7 < _local8) {
                _local9 = _local6.charAt(_local7);
                if (_local9 == PLACEHOLDER){
                    _local10 = _arg1.getSpriteByName(String(_local7));
					
					sDef.src = getQualifiedClassName(_local10);
					sDef.index = _local7-aIcons.length;
					
					
					trace(JSON.encode(sDef));
					aIcons.push(JSON.encode(sDef));
					
                    if (_local10){
                    	var h:int = _local10.height;
                    	var w:int = _local10.width;
                    	if( h > this._textfield.height){
                    		h = this._textfield.height;
                    		w = h;
                    	}
                        _textfield.replaceText((_local5 + _local7), ((_local5 + _local7) + 1), "");
                        addSprite(_local10, (_local5 + _local7),w, h);
                    };
                };
                _local7++;
            };
        }
        public function get type():String{
            return (_textfield.type);
        }
        public function get text():String{
            return (_textfield.text.split(PLACEHOLDER).join(""));
        }
        private function scrollHandler(_arg1:Event):void{
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:Number;
            var _local6:int;
            var _local7:Number;
            if (!_replacing){
                _local2 = ((_textfield.scrollV > _scrollV)) ? 1 : -1;
                _local3 = ((_local2 > 0)) ? (_textfield.scrollV - 2) : (_scrollV - 2);
                _local4 = ((_local2 > 0)) ? (_scrollV - 2) : (_textfield.scrollV - 2);
                _local5 = 0;
                _local6 = _local3;
                while (_local6 > _local4) {
                    _local5 = (_local5 + _textfield.getLineMetrics(_local6).height);
                    _local6--;
                };
                _local7 = (_spriteContainer.y - (_local2 * _local5));
                _spriteContainer.y = ((_local7 <= 0)) ? _local7 : 0;
            };
            _scrollV = _textfield.scrollV;
            
            if(this.vScrollBar){
            	vScrollBar.scrollPosition = _scrollV;
            }
        }
        private function createSpritesMask(x:Number, y:Number, w:Number, h:Number):Shape{
            var shape:Shape = new Shape();
            shape.graphics.beginFill(0xFF0000);
            shape.graphics.lineStyle(0, 0);
            shape.graphics.drawRect(x, y, w, h);
            shape.graphics.endFill();
            return (shape);
        }
        private function adjustSprites(_arg1:int, _arg2:int=1, _arg3:String="adjust_type_change"):void{
            var _local7:int;
            var face:Sprite;
            var _local9:Rectangle;
            var _local4:Boolean;
            var _local5:int;
            var _local6:int = numSprite;
            for (;_local5 < _local6;_local5++) {
                _local7 = getSpriteIndexAt(_local5);
                if (_local7 < (_arg1 - 1)){
                    continue;
                } else {
                    if ((((_local7 == _arg1)) && ((_arg3 == ADJUST_TYPE_CHANGE)))){
                        _local7 = (_local7 + _arg2);
                    } else {
                        if ((((((_local7 == (_arg1 - 1))) && ((_arg3 == ADJUST_TYPE_CHANGE)))) && ((_arg2 < 0)))){
                            continue;
                        } else {
                            if ((((((_local7 == (_arg1 - 1))) && ((_arg3 == ADJUST_TYPE_CHANGE)))) && ((_arg2 > 0)))){
                                _local7 = (_local7 + _arg2);
                            } else {
                                if ((((_local7 == (_arg1 - 1))) && ((_arg3 == ADJUST_TYPE_INSERT)))){
                                } else {
                                    if ((((_local7 == _arg1)) && ((_arg3 == ADJUST_TYPE_INSERT)))){
                                        if (((_local4) && ((_textfield.text.charAt((_arg1 + 1)) == PLACEHOLDER)))){
                                            if (_textfield.getTextFormat((_arg1 + 1)).letterSpacing != 0){
                                                _local7 = (_local7 + _arg2);
                                                _local4 = false;
                                            };
                                        } else {
                                            _local4 = true;
                                        };
                                    } else {
                                        if (_local7 != _arg1){
                                            _local7 = (_local7 + _arg2);
                                        };
                                    };
                                };
                            };
                        };
                    };
                };
                face = (_spriteContainer.getChildAt(_local5) as Sprite);
                _local9 = getCharBoundaries(_local7);
                if (((face) && (_local9))){
                    face.name = String(_local7);
                    setSpriteCoordinate(face, _local9);
                };
            };
        }
        private function getCharBoundaries(index:int):Rectangle{
            var _local3:int;
            var _local4:int;
            var _local2:Rectangle = _textfield.getCharBoundaries(index);
            if (!_local2){
                _local3 = _textfield.getLineIndexOfChar(index);
                if (_textfield.bottomScrollV < _local3){
                    _local4 = _textfield.scrollV;
                    _textfield.scrollV = _local3;
                    _local2 = _textfield.getCharBoundaries(index);
                    _textfield.scrollV = _local4;
                };
            };
            return (_local2);
        }
        public function addSprite(sprite:*, index:int=-1, w:Number=-1, h:Number=-1):void{
            var _local5:Class;
            var face:Sprite;
            if ((sprite is Class)){
                _local5 = sprite;
                face = (new (sprite) as Sprite);
            } else {
                face = sprite;
            };
            if (w > 0){
                face.width = w;
            };
            if (h > 0){
                face.height = h;
            };
            if (index == -1){
                index = _textfield.caretIndex;
            };
            if (index > _textfield.length){
                index = _textfield.length;
            };
            
            var holderFormat:TextFormat = getPlaceholderFormat(face.width, face.height);
            //var tf:TextFormat = this._defaultTextFormat;
            
            _replacing = true;
            var _local7:int = _textfield.scrollV;
            _textfield.replaceText(index, index, PLACEHOLDER);
            _textfield.setTextFormat(holderFormat, index);
            _textfield.scrollV = _local7;
            _replacing = false;
            var nh:int = face.height;
            var nw:int = face.width;
            if( nh > _textfield.height){
               //h = this._textfield.height;
               //w = h;
               face.scaleX=face.scaleY = 20./nh;
            }
            _spriteContainer.addChild(face);
            face.name = String(index);
            _length++;
            adjustSprites(index, 1, ADJUST_TYPE_INSERT);
            if (autoScroll){
                scrollTo(_textfield.maxScrollV);
            } else {
                if (autoScrollV > 0){
                    scrollTo(autoScrollV);
                };
            };
        }
        public function testString(_arg1:String):Boolean{
            return ((_arg1.indexOf(PLACEHOLDER) == -1));
        }
        public function removeSpriteByName(_arg1:String):void{
            var _local2:Sprite = (_spriteContainer.getChildByName(_arg1) as Sprite);
            if (_local2){
                _spriteContainer.removeChild(_local2);
            };
        }
       
        public function clear():void{
            _textfield.text = "";
           
            _length = 0;
            _scrollV = 1;
            recoverDefaultTextFormat();
            _format = new Dictionary();
            _spriteContainer.y = 0;
            while (_spriteContainer.numChildren > 0) {
                _spriteContainer.removeChildAt(0);
            };
        }
        public function set defaultTextFormat(_arg1:TextFormat):void{
            if (_arg1.letterSpacing == null){
                _arg1.letterSpacing = 0;
            };
            _defaultTextFormat = _arg1;
            _textfield.defaultTextFormat = _arg1;
        }
        private function recoverPlaceholderFormat(_arg1:int, _arg2:int):void{
            var _local4:Sprite;
            var _local5:TextFormat;
            var _local3:int = _arg1;
            while (_local3 < _arg2) {
                if (_textfield.text.charAt(_local3) == PLACEHOLDER){
                    _local4 = (_spriteContainer.getChildByName(String(_local3)) as Sprite);
                    if (!_local4){
                    } else {
                        _local5 = getPlaceholderFormat(_local4.width, _local4.height);
                        _textfield.setTextFormat(_local5, _local3);
                    };
                };
                _local3++;
            };
        }
        public function resize(_arg1:Number, _arg2:Number):void{
            _textfield.width = (_spriteMask.width = _arg1);
            _textfield.height = (_spriteMask.height = _arg2);
            adjustCoordinate(0, _textfield.length);
        }
        public function set text(_arg1:String):void{
            _arg1 = _arg1.split(PLACEHOLDER).join("");
            _textfield.text = _arg1;
        }
        public function getSpriteAt(_arg1:int):Sprite{
            if (_arg1 >= _spriteContainer.numChildren){
                return (null);
            };
            return ((_spriteContainer.getChildAt(_arg1) as Sprite));
        }
        public function replace(_arg1:String, _arg2:String, _arg3:int, _arg4:int):void{
            _arg1 = _arg1.split(PLACEHOLDER).join("");
            _arg2 = _arg2.split(PLACEHOLDER).join("");
            _textfield.text = ((_textfield.text.substring(0, _arg3) + _textfield.text.substring(_arg3, _arg4).split(_arg1).join(_arg2)) + _textfield.text.substring(_arg4));
            _length = (_length + (_arg2.length - _arg1.length));
            recoverPlaceholderFormat(0, length);
        }
        public function appendRichText(_arg1:String, _arg2:Array=null, _arg3:TextFormat=null, _arg4:Boolean=true):void{
            var _local5:int;
            var _local6:int;
            if (_arg1){
                appendText(_arg1, _arg3, _arg4);
            };
            if (_arg2){
                _local5 = 0;
                while (_local5 < _arg2.length) {
                    _local6 = _arg2[_local5].index;
                    if (_local6 == -1){
                        _local6 = _arg1.length;
                    } else {
                        if (_arg4){
                            _local6--;
                        };
                    };
                    _local6 = (_local6 + (_textfield.length - _arg1.length));
                    if (((_arg4) && ((_local6 >= _textfield.length)))){
                        _local6 = (_textfield.length - 1);
                    };
                    addSprite(_arg2[_local5].src, _local6, -1, lineHeight);
                    _local5++;
                };
            };
            if (autoScroll){
                scrollTo(_textfield.maxScrollV);
            } else {
                if (autoScrollV > 0){
                    scrollTo(autoScrollV);
                };
            };
        }
        public function get length():int{
            return (_textfield.text.length);
        }
        public function appendText(_arg1:String, _arg2:TextFormat=null, _arg3:Boolean=true):void{
            recoverDefaultTextFormat();
            var _local4:String = _arg1;
            if (_arg3){
                _local4 = (_local4 + "\n");
            };
            _local4 = _local4.split("\r").join("\n");
            var _local5:int = (_textfield.length - 1);
            _textfield.appendText(_local4);
            if (_arg2){
                _textfield.setTextFormat(_arg2, _local5, (_textfield.length - 1));
            }else{
            	 _textfield.setTextFormat(this._defaultTextFormat, _local5, (_textfield.length - 1));
            }
        }
        public function get textfield():TextField{
            return (_textfield);
        }
        public function set placeholderColor(_arg1:uint):void{
            PLACEHOLDER_COLOR = _arg1;
        }
        public function getSpriteIndexAt(_arg1:int):int{
            var _local2:Sprite = getSpriteAt(_arg1);
            if (_local2){
                return (int(_local2.name));
            };
            return (-1);
        }
        public function get textLength():int{
            return (text.length);
        }
        public function get format():Dictionary{
            return (_format);
        }
        public function set spriteVspace(_arg1:int):void{
            _spriteVspace = _arg1;
        }
        public function set type(_arg1:String):void{
            _textfield.type = _arg1;
            _textfield.addEventListener(Event.SCROLL, scrollHandler);
            if (_arg1 == INPUT){
                _textfield.addEventListener(Event.CHANGE, changeHandler);
                _textfield.addEventListener(TextEvent.TEXT_INPUT, inputHandler);
                _textfield.addEventListener(MouseEvent.MOUSE_UP, getSelectionHandler);
                _textfield.addEventListener(MouseEvent.MOUSE_OUT, getSelectionHandler);
            };
        }
        private function adjustCoordinate(_arg1:int=-1, _arg2:int=-1):void{
            var face:Sprite;
            var _local6:int;
            var r:Rectangle;
            var i:int;
            var num:int = _spriteContainer.numChildren;
            while (i < num) {
                face = (_spriteContainer.getChildAt(i) as Sprite);
                _local6 = int(face.name);
                if ((((_arg1 <= _local6)) && ((_arg2 >= _local6)))){
                    r = getCharBoundaries(_local6);
                    if (r){
                        setSpriteCoordinate(face, r);
                    };
                };
                i++;
            };
        }

    }
}//package com.riaidea.richtextfield 
